package com.limetalks.logic
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.media.Camera;
	import flash.media.Microphone;
	import flash.net.NetStream;
	
	public class AVCastManager extends EventDispatcher
	{
		private var limeTalks:LimeTalks;
		
		public function AVCastManager(limeTalks:LimeTalks)
		{
			super();
			this.limeTalks = limeTalks;
		}
		
		public function subscribeLiveCast(castId:String):NetStream 
		{
			var result:NetStream = new NetStream(limeTalks.connection);
			result.play(castId);
			return result;
		}
		
		public function publishLiveCast(enableCamera:Boolean = true, enableMicrophone:Boolean = true):NetStream 
		{
			var result:NetStream = null;
			//start publishing only if camera or microphone is enabled
			if(enableCamera || enableMicrophone){
				result = new NetStream(limeTalks.connection);
				if(enableCamera){
					result.attachCamera(Camera.getCamera());	
				}
				if(enableMicrophone){
					result.attachAudio(Microphone.getMicrophone());
				}
				result.publish(limeTalks.mySelf.id);
			}			
			return result;
		}
	}
}